package com.aidysoft.practice.log;

import java.io.*;
import java.nio.charset.Charset;

public class FileUtil {
    public static void uploadFile(byte[] file,String filePath,String fileName) {

        File targetFile=new File(filePath);
        if(!targetFile.exists()) {
            targetFile.mkdirs();
        }
        FileOutputStream outputStream= null;
        try {
            outputStream = new FileOutputStream(filePath+fileName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //System.out.println(filePath+"-------");
        try {
            outputStream.write(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            outputStream.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public  static  void  writeToFile(String filePath,String message){

        try{
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath,true), Charset.forName("utf-8")));
            bw.append(message+"\r\n\n");//注意需要转换对应的字符集

            bw.close();
        }catch(IOException e){
            e.printStackTrace();
        }
    }

}
